package com.excellent.item.mapper;


import com.excellent.item.pojo.Category;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.additional.idlist.SelectByIdListMapper;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * @author Xxacker
 *
 * 继承通用 Mapper ，并且指定泛型是 Category；
 * 通用 Mapper 还提供了 SelectByIdListMapper
 */
public interface CategoryMapper extends Mapper<Category>, SelectByIdListMapper<Category, Long> {
    @Select("SELECT ISPARENT, NAME, ID, SORT, PARENTID FROM TB_CATEGORY WHERE PARENTID = #{parentId}  ORDER BY SORT")
    List<Category> selectOrderBySort(Category category);

    /**
     * 根据品牌id查询商品分类
     * @param brandId
     * @return
     */
    @Select("SELECT * FROM TB_CATEGORY WHERE ID IN (SELECT CATEGORY_ID FROM TB_CATEGORY_BRAND WHERE BRAND_ID = #{brandId})")
    List<Category> queryByBrandId(Long brandId);

}
